<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="demo" index="1"></div>
    <script>
        var div = document.getElementById('demo');
        console.log(div.id);//只能获取元素自带属性
        console.log(div.index);//undefined
        //element.getAttribute('属性'); 我们程序员自己添加的属性 称为自定义属性
        console.log(div.getAttribute('id'));
        console.log(div.getAttribute('index'));
        //设置属性 与上面同理
        div.id = 'test';
        div.setAttribute('index', '2');
    </script>
</body>

</html>